﻿using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;

namespace SCM.Common
{
    public class PageInfo
    {
        public PageInfo()
        {
            this.PageIndex = 0;
            this.PageSize = 0;
            this.DataCount = 0;
        }
        public PageInfo(int pageIndex = 1, int pageSize = 20, int dataCount = 0)
        {
            this.PageIndex = pageIndex;
            this.PageSize = pageSize;
            this.DataCount = dataCount;
        }
        /// <summary>
        /// 总页数
        /// </summary>
        [JsonProperty("pageCount")]
        public int PageCount
        {
            get
            {
                if (PageSize > 0)
                {
                    return dataCount / PageSize + dataCount % PageSize == 0 ? 0 : 1;
                }
                return 0;
            }
        }

        /// <summary>
        /// 当前页码
        /// </summary>
        [JsonProperty("pageIndex")]
        [Required(ErrorMessage = "页码不能为空")]
        public int PageIndex { get; set; }
        /// <summary>
        /// 单页条数
        /// </summary>
        [Required(ErrorMessage = "单页条数不能为空")]
        [JsonProperty("pageSize")]
        public int PageSize { get; set; }
        private int dataCount = 0;
        /// <summary>
        /// 总条数
        /// </summary>
        [JsonProperty("dataCount")]
        public int DataCount
        {
            get { return dataCount; }
            set
            {
                dataCount = value;
            }
        }
    }
}
